package com.acme.bankapp.domain.bank;

import java.io.Serializable;

public class Client implements Serializable{
	private static final long serialVersionUID = -3727741531278846656L;
	private String name;
	private Gender gender;
	private Account account;

	
	public Client() {
	}

	public Client(String name, Gender gender) {
		this.name = name;
		this.gender = gender;
	}

	public Client(String name, Gender gender, Account account) {
		this.name = name;
		this.gender = gender;
		this.account = account;
	}

	public Client(Account account) {
		this.account = account;
	}

	public void addAccount(Account account){
		this.account = account;
	}
	
	public Account getAccount() {
		return account;
	}

	protected String getName() {
		return name;
	}

	protected Gender getGender() {
		return gender;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setGender(Gender gender) {
		this.gender = gender;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	public String getClientSalutation() {
		return getGender().getSalutation() + getName();
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((account == null) ? 0 : account.hashCode());
		result = prime * result + ((gender == null) ? 0 : gender.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Client other = (Client) obj;
		if (account == null) {
			if (other.account != null)
				return false;
		} else if (!account.equals(other.account))
			return false;
		if (gender != other.gender)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(getClientSalutation()).append(": ").append(account == null ? "no accaount" : account.toString());
		return sb.toString();
	}
}
